package com.marver.sys.controller;

import com.marver.beans.UserInfoQo;
import com.marver.common.result.Result;
import com.marver.common.result.ResultStatus;
import com.marver.common.utils.ValidDataUtil;
import com.marver.common.utils.group.AddGroup;
import com.marver.entity.qo.Param;
import com.marver.sys.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 用户controller
 * @Author: Marver
 * @date: 2018-04-27 15:46
 **/
@RestController
@RequestMapping("/sys/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * @Author: Marver
     * @Description: 添加用户
     * @Date: 2018/4/27 16:20
     * @params [param]
     */
    @PostMapping("/add")
    @RequiresPermissions("sys:user:add")
    public Result addUser(@RequestBody Param<UserInfoQo> param) {
        ValidDataUtil.validateEntity(param.getBody(), AddGroup.class);

        userService.saveUser(param.getBody());
        return new Result(ResultStatus.SUCCESS.getErrorCodeToString(),"SUCCESS");
    }


    @PostMapping("/list")
    @RequiresPermissions("sys:user:list")
    public Result queryUserList(@RequestBody Param<UserInfoQo> param) {
        return userService.queryUserList(param);
    }
}
